package com.tsingteng.cosfun.ui.message.comment.usercomment;

import android.util.Log;

import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.Bean;
import com.tsingteng.cosfun.bean.ParagraphComment;
import com.tsingteng.cosfun.bean.PlayCommont;
import com.tsingteng.cosfun.bean.PullBlackBean;
import com.tsingteng.cosfun.bean.UserCommentResultBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.utils.ToastUtils;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @我。赞我。评论我页面点击展示段子评论页P层
 * 常胜
 * 2018.8.23
 * */
public class UserCommentPresenter implements  UserCommentContract.IUserCommentPresenter{


    private final UserCommentModel userCommentModel;
    private UserCommentContract.IUserCommentView view;

    public UserCommentPresenter(UserCommentFragment userCommentFragment) {
        view= userCommentFragment;
        userCommentModel = new UserCommentModel();
    }

    @Override
    public void getPlayCommentList(int workId, int page, String commentIds) {
        userCommentModel.getPlayCommentListResponse(workId, page, commentIds,new Callback<BaseDataBean<PlayCommont>>() {
            @Override
            public void onResponse(Call<BaseDataBean<PlayCommont>> call, Response<BaseDataBean<PlayCommont>> response) {
                view.showCommentListResult(response.body().data);
            }

            @Override
            public void onFailure(Call<BaseDataBean<PlayCommont>> call, Throwable t) {
                Log.e("onFailure", t.toString());
            }
        });
    }

    @Override
    public void getMyPlayComment(int id, String content_type, int commentId, String content, String reply_id) {
        userCommentModel.getMyPlayCommentResponse(id, content_type, content, reply_id, commentId,new Callback<UserCommentResultBean>() {
            @Override
            public void onResponse(Call<UserCommentResultBean> call, Response<UserCommentResultBean> response) {
                UserCommentResultBean body = response.body();
                if(body != null){
                    view.showMyPlayCommentResult(body);
                }
            }

            @Override
            public void onFailure(Call<UserCommentResultBean> call, Throwable t) {

            }
        });
    }

    @Override
    public void getPraiseOrNotData(String praise_type, String id, String type) {
        userCommentModel.getPraiseOrNot(praise_type, id, type, new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                if(response.body()==null)return;
                view.showPraiseResult(response.body().getData());
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                Log.e("onFailure",t.getMessage());
            }
        });
    }

    @Override
    public void loginDeleteComment(int commentId) {
        userCommentModel.getDeleteCommentResponse(commentId, new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                    view.showDeleteCommentResult(response.body());
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                    Log.e("onFailure",t.getMessage());
            }
        });
    }

    @Override
    public void getAddPlayComment(String paragraph_id, String comment_type, String content, String comment_object_id) {
        userCommentModel.getAddPlayComment(paragraph_id, comment_type, content, comment_object_id, new Callback<BaseDataBean<ParagraphComment>>() {
            @Override
            public void onResponse(Call<BaseDataBean<ParagraphComment>> call, Response<BaseDataBean<ParagraphComment>> response) {
                if (response.body()== null)return;
                view.showAddCommentResult(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseDataBean<ParagraphComment>> call, Throwable t) {
                view.showFail("网络错误,请稍后重试!");
            }
        });

    }
}
